package com.gking.centerSystem.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gking.centerSystem.common.Result;
import com.gking.centerSystem.entity.Routes;
import com.gking.centerSystem.service.Routes.RoutesService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Slf4j
@RestController
@RequestMapping("/routes")
public class RoutesController {

    @Resource
    private RoutesService routesService;

    /**
     * 获取页面路由列表
     *
     * @param sortId 分类id
     * @param size   分页大小
     * @param page   分页页码
     * @return s
     */
    @RequiresPermissions("CS:manager:get:routes")
    @GetMapping("/routesList")
    public Result<Page> getRoutesList(@RequestParam String sortId, @RequestParam Integer size,
                                      @RequestParam Integer page) {
        return routesService.getRoutesList(sortId, size, page);
    }

    /**
     * 获取分类下的所有路由
     *
     * @param sortId 分类id
     * @return s
     */
    @RequiresPermissions("CS:manager:get:routes")
    @GetMapping("/allSortRoutes")
    public Result<List<Routes>> getAllSortRoutes(@RequestParam String sortId) {
        return routesService.getAllSortRoutes(sortId);
    }

    /**
     * 创建页面路由或者修改页面路由信息
     *
     * @param route 路由信息
     * @return s
     */
    @RequiresPermissions("CS:manager:set:routes")
    @PostMapping("/setRoute")
    public Result<String> setRoute(@RequestBody Routes route) {
        return routesService.setRoute(route);
    }

    /**
     * 批量删除页面路由
     *
     * @param routeIdList 路由id列表
     * @return s
     */
    @RequiresPermissions("CS:manager:set:routes")
    @PostMapping("/deleteRoutes")
    public Result<String> deleteRoutes(@RequestBody List<String> routeIdList) {
        return routesService.deleteRoutes(routeIdList);
    }

    /**
     * 批量更新路由状态
     *
     * @param routeIdList 路由id 列表
     * @param status      状态 0启用，1禁用
     * @return s
     */
    @RequiresPermissions("CS:manager:set:routes")
    @PostMapping("/updateRoutesStatus")
    public Result<String> updateRoutesStatus(@RequestBody List<String> routeIdList, @RequestParam Integer status) {
        return routesService.updateRoutesStatus(routeIdList, status);
    }

}
